//
//  PreviewViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/11/18.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "PreviewViewController.h"

@interface PreviewViewController ()



@end

@implementation PreviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"商品预览";
    self.backBtn.hidden = NO;
    self.view.backgroundColor = BACKGROUND1;
    
    
    if ([self.nameKey isKindOfClass:[NSNull class]] || self.nameKey.length == 0)
    {
        
        [self.view makeToast:@"后台妹妹忘记上传商品照片啦"];
        
        return;
    }
    

    
}





-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;

}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{


    return 8;



}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
        return 140;
        
    }
    
    else if (indexPath.row == 7)
    {
        return 180;
    
        
    }
    
    else
    {
    
        return 44;
    
    }



}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 0.001;

}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 44;

}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{

    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view2.backgroundColor = BACKGROUND1;
    [self.view addSubview:view2];
    return view2;


}








-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
         cell.backgroundColor = [UIColor whiteColor];
        cell.textLabel.textColor = [UIColor grayColor];
        //设定副标题
        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(ViewWidth *0.45, 0,  ViewWidth *0.55-10, 44)];
        lbl.font = [UIFont systemFontOfSize:15];
        lbl.textAlignment = NSTextAlignmentRight;
        lbl.textColor = [UIColor lightGrayColor];
        lbl.tag = 102;
        [cell addSubview:lbl];
        
    }
    
    
    UILabel *sublabel = (UILabel *) [cell viewWithTag:102];

    if (indexPath.row == 0) {
      
     
        NSURL *url = [NSURL URLWithString:self.nameKey];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((ViewWidth - 140)/2, 0, 140, 140)];
        imageView.image = [UIImage imageWithData:data];
        

        [cell addSubview:imageView];
        
 
        sublabel.hidden = YES;

        
        
    }
    
    
    
    
    
    
    if (indexPath.row == 1) {
        
        cell.textLabel.text = @"商品名称 :";
        
        sublabel.text = self.textName;
        
        
    }

    else if (indexPath.row == 2)
    {
    
    cell.textLabel.text = @"商品分类 :";
        sublabel.text = self.textFenlei;
    
    }
//    else if (indexPath.row == 3)
//    {
//    
//    cell.textLabel.text = @"商品产地 :";
//        sublabel.text = self.textChandi;
//        sublabel.font = [UIFont systemFontOfSize:15];
//    
//    }
    else if (indexPath.row == 3)
    {
        
        cell.textLabel.text = @"商品规格 :";
        sublabel.text = self.guiGe;
        
    }
    else if (indexPath.row == 4)
    {
        
        cell.textLabel.text = @"商品单价 :";
        sublabel.text = self.textPrice;
          sublabel.text = [NSString stringWithFormat:@"%@ 元",self.textPrice];
        
    }
    else if (indexPath.row == 5)
    {
    
        cell.textLabel.text = @"商品均价 :";
             sublabel.text = [NSString stringWithFormat:@"%@ 元/斤",self.textJunjia];
      

    
    }
//    else if (indexPath.row == 7)
//    {
//        
//        cell.textLabel.text = @"商品库存 :";
//        sublabel.text = self.textKucun;
//        
//    }
    else if (indexPath.row == 6)
    {
        
        cell.textLabel.text = @"联系方式 :";
        sublabel.text = self.textphone;
        
    }
    else if (indexPath.row == 7)
    {
        

        sublabel.hidden = YES;
        sublabel.text = self.textDescribe;
        
        
        UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, 220)];
        textView.font = [UIFont systemFontOfSize:16];
        textView.textColor = [UIColor lightGrayColor];
        textView.text = [NSString stringWithFormat:@"   %@",self.textDescribe];
        textView.editable = NO;
        [cell addSubview:textView];
        
    }
    
    
    return cell;

}

@end
